<template>
  <header class="header">
    <h1>todos</h1>
    <input id="toggle-all" class="toggle-all" type="checkbox" v-model="isAll">
    <label for="toggle-all"></label>
    <input
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
      @keydown.enter="enterFn"
      v-model.trim="$store.state.taskName"
    />
  </header>
</template>

<script>
export default {
  data(){
    return{
     
    }
  },
 methods:{
  //  按下输入框值赋给父组件
   enterFn(){
    //  console.log("按下了回车键"+this.task);
    if(!this.$store.state.taskName) return alert("不可以为空哦")
    this.$store.commit('addTask',this.$store.state.taskName)
    this.$store.state.taskName=''
   }
 },
 computed:{
    isAll:{
      set(val){
        // console.log(val);
        this.$store.getters.list.forEach(obj =>obj.isDone=val);
      },
      get(){
        return this.$store.getters.list.every(item=>item.isDone===true)
      }

    }
  },
}
</script>
